<template>
	<view>
		<u-navbar back-icon-name="integral">
			<my-fenlei-search style="width: 100%;" @myClick="gotoSearch()"></my-fenlei-search>
		</u-navbar>
		<view class="scroll-view-container">
			<scroll-view class="left-scroll-view" :style="{height:wh+'px'}"  scroll-y="true" >
				<block v-for="(item,index) in cateList" :key="index">
					<view @click="activeChanged(index)" :class="['left-scroll-view-item',index === active && 'active']" >{{item.cat_name}}</view>
				</block>
				
				
			</scroll-view>
			<scroll-view class="right-scroll-view" :style="{height:wh+'px'}" :scroll-top="scrollTop" scroll-y="true" >
				<view v-for="(item,index) in cateLevel2" :key="index">
					<view class="cate-lv2-title">/{{item.cat_name}}/</view>
					
					<view class="cate-lv3-list">
						<view @click="gotoGoodsList(item2)" class="cate-lv3-item" v-for="(item2,index2) in item.children" :key="index2">
							<image :src="item2.cat_icon" ></image>
							<text>{{item2.cat_name}}</text>
						</view>
					</view>
					
				</view>
				
			</scroll-view>
		</view>
		<u-tabbar :list="tabbar"></u-tabbar>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	import badgeMix from '../../mixins/tabbar-badge.js'
	
	export default {
		data() {
			return {
				wh:0,
				cateList:[],
				active:0,
				cateLevel2:[],
				scrollTop:0,
			};
		},
		mixins:[badgeMix],
		computed:{
			...mapState(['tabbar']),
		},
		onLoad(){
			this.wh = uni.getSystemInfoSync().windowHeight - 68
			console.log(uni.getSystemInfoSync().windowHeight)
			this.getCateList()
		},
		methods:{
			async getCateList(){
				let {data} = await uni.$http.get('/api/public/v1/categories')
				if(data.meta.status !== 200) return uni.$showMsg()
				this.cateList = data.message
				this.activeChanged()
			},
			activeChanged(i=0){
				this.active = i
				this.cateLevel2 = this.cateList[i].children
				this.scrollTop = this.scrollTop === 0?1:0
			},
			gotoGoodsList(item){
				console.log(item)
				uni.navigateTo({
					url:'/subpkg/goods_list/goods_list?cid='+item.cat_id
				})
			},	
			gotoSearch(){
				uni.navigateTo({
					url:'../../subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	
	page{
		overflow: hidden;
		// padding-bottom: 30px;
	}
	
	.cate-lv3-list{
		display: flex;
		flex-wrap: wrap;
		
		.cate-lv3-item{
			width: 33.333%;
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-bottom: 10px;
			
			
			image{
				width: 60px;
				height: 60px;
			}
			
			text{
				font-size: 12px;
			}
		}
	}

.scroll-view-container{
	display: flex;
	
	.left-scroll-view{
		width: 120px;
		background-color: #f7f7f7;
		
		.left-scroll-view-item{
			line-height: 120rpx;
			text-align: center;
		}
	}
}

.active{
	background-color: #FFFFFF;
	position: relative;
	
	&::before{	
		content: '';
		position: absolute;
		left: 0;
		transform: translateY(-50%);
		top: 50%;
		height: 80%;
		width: 5rpx;
		background: #ff0000;
	}
}

.cate-lv2-title {
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  padding: 15px 0;
}

</style>
